//
//  PPMyQRCodeViewController.m
//  pet
//
//  Created by Frank on 9/6/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPUserQRCodeViewController.h"
#import "QRCodeGenerator.h"
#import "supportingHeadFiles.h"
#import "SBJson.h"

#import "PPSystemConfiguraton.h"

@interface PPUserQRCodeViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *avatarImageView;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *QRCodeImageView;
@property (weak, nonatomic) IBOutlet UIView *QRCodeBackGroundView;

@property (weak, nonatomic) IBOutlet UILabel *hintLabel;

@end

@implementation PPUserQRCodeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(self.user.id == [PPSystemConfiguraton sharedSystemConfiguration].userInfo.id)
    {
        [self.navigationItem setTitle:@"我的二维码"];
        self.hintLabel.text = @"扫一扫二维码，加我好友";
    }else{
        switch (self.user.gender) {
            case 0:
                [self.navigationItem setTitle:@"他的二维码"];
                self.hintLabel.text = @"扫一扫二维码，加他好友";
                break;
            case 1:
                [self.navigationItem setTitle:@"她的二维码"];
                self.hintLabel.text = @"扫一扫二维码，加她好友";
                break;
            default:
                break;
        }
        
        
    }
    
    
    
    [self.avatarImageView setImageWithURL:[PPImageUrl getImageUrl:self.user.userAvatar] placeholderImage:[UIImage imageNamed:@"defaultAvatar"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    
    NSDictionary *userIdDic = @{@"userid": @(self.user.id)};
    NSString *userIdString = [userIdDic JSONRepresentation];
    self.QRCodeImageView.image = [QRCodeGenerator qrImageForString:userIdString imageSize:self.QRCodeImageView.bounds.size.width];
    self.userNameLabel.text = self.user.userName;
    
    self.QRCodeBackGroundView.layer.masksToBounds = YES;
    self.QRCodeBackGroundView.layer.cornerRadius = 5;
    self.avatarImageView.layer.masksToBounds = YES;
    self.avatarImageView.layer.cornerRadius = 2;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
